<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String contextPath = request.getContextPath(); %>
<%@page import="common.*" %>
<%@ page import="java.util.*" %>
<%
	Customer user = (Customer)session.getAttribute("user");
	Cart cart = (Cart)session.getAttribute("cart");
	List<OrderItem> list = cart.getItems();
	int total_price = 0;
	int fee = 0;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<%= contextPath %>/css/style.css" rel="stylesheet" type="text/css" />
		<link href="<%= contextPath %>/css/sidemenu.css" rel="stylesheet" type="text/css" />
		<link href="<%= contextPath %>/css/regi.css" rel="stylesheet" type="text/css" />
		<title>レジ</title>
	</head>
	<body>
		<div id="wrapper">
			<div id="sidemenu"">
				<jsp:include page="sidemenu.jsp" flush="true"/>
			</div>
			<div id="contents">
				<h2>レジ</h2>
				<form action="<%= contextPath %>/orderCus/OrderCheckServlet">
					<table border="1" cellpadding="0">
						<tr>
							<th>商品名</th>
							<th>商品コード</th>
							<th>規格</th>
							<th>売単価</th>
							<th width="60px">注文数</th>
							<th width="90px">金額</th>
						</tr>
						<% for(int i=0; i<list.size(); i++)
							{
								OrderItem oi = list.get(i);
								Item item = Item.find_by_code(oi.getItem_code());%>
						<tr>
							<td><%= item.getName() %></td>
							<td><%= item.getCode() %></td>
							<td><%= item.getSize() %></td>
							<td><%= item.getPrice() %>円</td>
							<td><%= oi.getOrders() %></td>
							<td>
								<%= (item.getPrice() * oi.getOrders()) %>円
								<input type="hidden" name="price_total"value="<%= (item.getPrice() * oi.getOrders()) %>">
								<input type="hidden" name="cost_total"value="<%= (item.getCost() * oi.getOrders()) %>">
							</td>
						</tr>
							<% total_price = total_price + (item.getPrice() * oi.getOrders()); %>
						<% } %>
					</table>
					<div>
						<div id="regi">
							<table border="1" cellpadding="0" id="regitable" align="right">
								<tr>
									<td class="right">合計</td>
									<td class="left">
										<%= total_price %>円
										<input type="hidden" name="total_price" value="<%= total_price %>"/>
									</td>
								</tr>
								<tr>
									<td class="right">配送料</td>
									<% if(total_price < 10000) fee = 500; %>
									<td class="left"><%= fee %>円</td>
								</tr>
								<tr>
									<td class="right">合計金額</td>
									<td class="left"><%=(total_price + fee) %>円</td>
								</tr>
							</table>
						</div>
						<div id="deli">
							お届け希望日
							<select name="deliver">
								<option selected="selected" value="1">指定しない</option>
								<option value="2">2日後</option>
								<option value="3">3日後</option>
								<option value="4">4日後</option>
								<option value="5">5日後</option>
								<option value="6">6日後</option>
								<option value="7">7日後</option>
							</select>
						</div>
						<div></div>
					</div>
					<br clear="right">
					<div align="left">お客様情報</div>
					<table border="1" id="cs">
						<tr>
							<td>顧客コード</td>
							<td><%= user.getCode() %></td>
						</tr>
						<tr>
							<td>お客様名</td>
							<td><%= user.getName() %></td>
						</tr>
						<tr>
							<td>お届け先住所</td>
							<td><%= user.getAddress() %></td>
						</tr>
						<tr>
							<td>電話番号</td>
							<td><%= user.getTel() %></td>
						</tr>
						<tr>
							<td>クレジットカード番号</td>
							<td>************<%= user.getCard().substring(user.getCard().length()-4) %></td>
						</tr>
					</table>
					<input type="hidden" name="fee" value="<%= fee %>"/>
					<input type="submit" value="確定する" id="btn" />
				</form>
				<form action="<%= contextPath %>/customer/cart.jsp" >
					<input type="submit" value="カートに戻る" id=btn2 />
				</form>
				<br clear="left" />
			</div>
		</div>
	</body>
</html>
